The video below shows setting up a system integration process to import profile (ie customer) data from a remote source.
This process matched existing customers where possible, and when new information allows existing profiles to be identified as duplicates merges them.
This is just a simple introduction, the matching API offers many more factors for matching profiles.
Source code used in the demo
controllers.xml
<integration>
<!-- Carters To EMC -->
<endpoint
id='IMPORT-CUSTS'
type='sftp-fetching'
execIdTemplate="IMPORT-CUSTS"
address="sftp://10.10.10.10:222/upload"
fileName="@{formatter.formatJodaDate(formatter.addDays(formatter.now, -1), 'ddMMyyyy', pipeline.org().timezone)}.emc"
username="XXX"
password="XXX"
pipelinePath='/integration/import-custs.xml'
storeFile='true'
direction='in'
enabled='true'
/>
</integration>
import-custs.xml
<TransactionStep>
<next class="CsvInput" separator="," startRow="1">
<next class="JsRowStep">
<jsPath>/integration/check-custs.js</jsPath>
<execFn>checkCusts</execFn>
<next class="DatabaseUpdateStep" providerId="profile" mode="updateOrInsert">
<column field="firstName" columnName="A"/>
<column field="surName" columnName="B"/>
<column field="phone" columnName="C"/>
<column field="email" columnName="D"/>
<column field="userId" columnName="E"/> <!-- Injected by JS based on matching logic -->
<column field="group" valueString="customers"/>
</next>
</next>
</next>
</TransactionStep>
check-custs.js
function checkCusts(firstName, surName, phone, email) {
var matchReq = userManager.newProfileMatchRequest().or();
// this will return all profiles matching all given non-blank params
if( email ) {
matchReq.newSubCriteria().and()
.firstName(firstName)
.email(email);
}
if( phone ) {
matchReq.newSubCriteria().and()
.firstName(firstName)
.phone(phone);
}
var matched = userManager.findMatching(matchReq);
log.info("Matched {} profiles", matched.size());
if( matched.size() == 0 ) {
nextStep.exec(firstName, surName, phone, email, null);
} else if( matched.size() == 1) {
var existing = matched.get(0);
nextStep.exec(firstName, surName, phone, email, existing.userName);
} else {
// Choose the first as the merge target. Merge others into that, and then continue with it
var mergeDest = matched.get(0);
matched.remove(0);
userManager.mergeProfiles(mergeDest, matched);
nextStep.exec(firstName, surName, phone, email, mergeDest.userName);
}
}
Hide comments